{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "65e3868b-97f7-4dc6-8af8-7e2f30c6a9ae",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "2fc66ecd-c2b0-4f95-b9aa-1894cde649ba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "30"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "add = lambda x, y: x + y\n",
    "\n",
    "add(10, 20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "bf361568-764e-4159-897f-62ef2382aa04",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "30"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(lambda x, y: x + y)(10, 20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "93e38af8-108e-4c95-8d0e-8956b48a0d9d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ffba5f71-16c4-48a0-ab10-6cbc2edf1385",
   "metadata": {},
   "outputs": [],
   "source": [
    "s = [30, 10, 20, 40, 15]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "86f685ee-d546-4fb2-b817-c7f0e6e5cf79",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 15, 20, 30, 40]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sorted(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7e0fa533-1bf3-40de-8ca7-f84e624c4d6a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "14b92d76-803a-4ce9-8082-9fd9c3011982",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-30"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(lambda x: -x)(30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5577a1ba-ebb5-465c-940b-134a05421292",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "90c488ff-4549-433e-8542-e6f103ea02bf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[40, 30, 20, 15, 10]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sorted(s, key=lambda x: -x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ef9ff4b6-52c8-4319-bd09-6e63b689e46a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "0bb03ab7-6dc0-4324-8767-0388909b5a58",
   "metadata": {},
   "outputs": [],
   "source": [
    "s = [('A', 10), ('B', 20), ('C',40), ('C', 15)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a5261cc8-789e-4f04-b02f-e0cb23f0cf1a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('A', 10), ('B', 20), ('C', 15), ('C', 40)]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sorted(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "811ce386-0ef9-4798-bfa2-8ebf5360f8fa",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "0a79e575-0fe8-46e4-a449-79a9070f0fc7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('A', 10), ('C', 15), ('B', 20), ('C', 40)]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sorted(s, key=lambda x: x[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "11e593e2-1d1b-4224-b350-c4acaf778868",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "3d33df6d-c82f-4200-ba06-d7bde79feeeb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('A', 10), ('C', 15), ('B', 20), ('C', 40)]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def sort_by_2nd(x):\n",
    "    return x[1]\n",
    "    \n",
    "sorted(s, key=sort_by_2nd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3babf48e-2fc7-46e5-a700-176ea8feb2f2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a8a43a9b-dc1a-46cd-ae68-5282b71b0357",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
